package com.mmlc.utils;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.androidnetframe.BaseParentActivity;
import com.androidnetframe.httputil.BaseRequestFilterLayer;
import com.androidnetframe.responsejavabean.RequestError;
import com.mmlc.meimei.lichengkongjian.brand.BrandInfoActivity;
import com.mmlc.meimei.lichengkongjian.classify.ActivityPhotoView;
import com.mmlc.meimei.lichengkongjian.classify.CategoryListActivity;
import com.mmlc.meimei.lichengkongjian.classify.FastGoodsDetailActivity;
import com.mmlc.meimei.lichengkongjian.classify.MeiQiFastBuyActivity;
import com.mmlc.meimei.lichengkongjian.classify.ProductInfoActivity;
import com.mmlc.meimei.lichengkongjian.home.WebViewActivity;
import com.mmlc.network.filter.DeviceRequestFilter;
import com.mmlc.network.responsebean.BannerResponseBean;
import com.mmlc.network.responsebean.DeviceResponseBean;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/8/17.
 */
public class DataUtils {
    public static void toJump(Context context, int posotion, ArrayList<String> list) {
        Intent intent = new Intent(context,ActivityPhotoView.class);
        Bundle bundle1 = new Bundle();
        bundle1.putString("index",posotion+"");
        bundle1.putStringArrayList("imgs",list);
        intent.putExtra("bundle",bundle1);
        context.startActivity(intent);

    }

    public static void toJump(Context context, BannerResponseBean.AdListBean data) {
        if (!ViewUtils.isEmpty(data.getType())) {
            /**  0跳转网页 4商品详情 5商品列表页(分类) 6商品列表页(品牌) */
            Intent intent = null;
            if ("0".equals(data.getType())) {
                if(data.getUrl() == null || data.getUrl().equals("") || data.getUrl().equals("/")){
                    return;
                }
                intent = new Intent(context, WebViewActivity.class);
                intent.putExtra("title", data.getName())
                        .putExtra("url",  /*data.getUrl()*/new WebAddress(data.getUrl()).toString())
                        .putExtra("shareImageUrl", data.getImg());
            } else if ("4".equals(data.getType())) {
                intent = new Intent(context, ProductInfoActivity.class);
                intent.putExtra("name", data.getName()).putExtra("goods_id", data.getUrl());
            } else if("41".equals(data.getType())){
                intent = new Intent(context, FastGoodsDetailActivity.class);
                intent.putExtra("name", data.getName()).putExtra("url", data.getUrl());
            } else if ("5".equals(data.getType())) {
                intent = new Intent(context, CategoryListActivity.class);
                intent.putExtra("category", data.getName())
                        .putExtra("categoryId", data.getUrl())
                        .putExtra("relation_pos_id", data.getRelation_pos_id());
            } else if ("6".equals(data.getType())) {
                intent = new Intent(context, BrandInfoActivity.class);
                intent.putExtra("name", data.getName()).putExtra("brand_id", data.getUrl());
            }else if("51".equals(data.getType())){
                intent = new Intent(context, MeiQiFastBuyActivity.class);
                intent.putExtra("cate_id",data.getUrl());
            }
            if (intent != null) {

                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            }
        }
    }

    /**
     * 上传设备信息
     */
    public static void postDevice(BaseParentActivity activity) {
        DeviceRequestFilter filter = new DeviceRequestFilter(activity);
        filter.requestBean.m = PhoneUtils.getModel();
        filter.requestBean.v = PhoneUtils.getPhoneVersion();
        filter.requestBean.av = PhoneUtils.getAndroidVersion();
        filter.requestBean.sc = PhoneUtils.getCPU(activity);
        filter.requestBean.sr = PhoneUtils.getTotalMemory(activity);
        filter.requestBean.ahd = PhoneUtils.getAvailMemory(activity);
        filter.requestBean.bb = PhoneUtils.getBB();
        filter.requestBean.c = PhoneUtils.getKernelVersion();
        filter.requestBean.n = PhoneUtils.getProvidersName(activity);
        filter.requestBean.i = PhoneUtils.getIMEI(activity);
        filter.requestBean.mac = PhoneUtils.getMac(activity);
        filter.requestBean.fc = PhoneUtils.getForeCameraSupport(activity);
        filter.requestBean.bc = PhoneUtils.getBackCameraSupport(activity);
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<DeviceResponseBean>() {
            @Override
            public void onSuccess(DeviceResponseBean result) {


            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {
            }
        });
    }

}
